<?php

abstract class openapi_api_function_abstract extends openapi_api_function_base{

    function __construct()
    {
        //自动开启session
        $_GET['sess_id'] = $_POST['login_token'];
        $sess = kernel::single('base_session');
        $sess->start();
        $sess->set_sess_expires(720);//设置登录过期时间
        $this->member_id = $_SESSION['account'][pam_account::get_account_type(app::get('b2c')->app_id)];
    }

    public function checklogin($login_token)
    {
        if(empty($_SESSION['account'][pam_account::get_account_type(app::get('b2c')->app_id)])){
            return false;
        }else{
            return $_SESSION['account'][pam_account::get_account_type(app::get('b2c')->app_id)];
        }
    }

    //避免方法名用错多加的方法  与下面方法相同
    public function get_member_info()
    {
        return app::get('b2c')->model('members')->get_member_info($this->member_id);
    }

    public function get_current_member()
    {
        $obj_members = app::get('b2c')->model('members');
        $member = $obj_members->get_current_member();
        return $member;
    }

    function get_start($nPage,$pagesize,$count){
        $maxPage = ceil($count / $pagesize);
        if($nPage > $maxPage) $nPage = $maxPage;
        $start = ($nPage-1) * $pagesize;
        $start = $start<0 ? 0 : $start;
        $aPage['start'] = $start;
        $aPage['maxPage'] = $maxPage;
        return $aPage;
    }

    function pagination($current,$totalPage,$act,$arg='',$app_id='b2c',$ctl='site_member'){ //本控制器公共分页函数
        if (!$arg){
            $pagedata = array(
                'current'=>$current,
                'totalpage'=>$totalPage,
                );
        } else {
            $arg = array_merge($arg, array(($tmp = time())));
            $pagedata = array(
                'current'=>$current,
                'totalpage'=>$totalPage,
                );
        }
        return $pagedata;
    }
    
}